package com.engine4cloud.tdf.education.controller.web;

import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.data.web.response.Params;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.education.dto.query.PsychologicalCounsellingAttendQuery;
import com.engine4cloud.tdf.education.dto.result.PsychologicalCounsellingAttendResultDTO;
import com.engine4cloud.tdf.education.dto.update.PsychologicalCounsellingAttendUpdateDTO;
import com.engine4cloud.tdf.education.service.PsychologicalCounsellingAttendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 心理辅导参加人管理
 *
 * @author wenjie
 * @date 2024-08-13 16:58:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/psychological/counselling/attend")
@Tag(description = "eduPsychologicalCounsellingAttend", name = "心理辅导参加人管理-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PsychologicalCounsellingAttendController {

    private final PsychologicalCounsellingAttendService psychologicalCounsellingAttendService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param dto  心理辅导
     * @return R<PageInfo < EduPsychologicalCounsellingResultDTO>>
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R<PageInfo<PsychologicalCounsellingAttendResultDTO>> pageList(@ParameterObject Params page, @Valid @ParameterObject PsychologicalCounsellingAttendQuery dto) {
        return R.ok(psychologicalCounsellingAttendService.pageList(page, dto));
    }


    /**
     * 通过id查询心理辅导参加人
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<PsychologicalCounsellingAttendResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(psychologicalCounsellingAttendService.getById(id));
    }

    /**
     * 批量修改心理辅导参加人
     *
     * @param dto 心理辅导参加人
     * @return R
     */
    @Operation(summary = "批量修改心理辅导参加人", description = "批量修改心理辅导参加人")
    @SysLog("批量修改心理辅导参加人")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('psychological_attend_edit')")
    public R<Boolean> updateBatch(@Valid @RequestBody List<PsychologicalCounsellingAttendUpdateDTO> dto) {
        return R.ok(psychologicalCounsellingAttendService.updateBatch(dto));
    }
}